package com.codyy.felix.webconsole.plugins.route.core.pojo;

import com.codyy.felix.webconsole.plugins.route.core.RouteService;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

public class RouteResult implements IResult, Serializable {
// Serializables

	private  String id;

	private String provider;

	private String label;


	/**状态*/
	private String state;

	private Map<String, Object> context;

	// Internally used for post-processing

	private transient int rank;


	private transient List<String> phrases;

	public RouteResult () {

	}
	public RouteResult(String provider, String id, int rank, String label) {
		this.provider = provider;
		this.rank = rank;
		this.label = label;
		this.context = Maps.newHashMap();

		this.id = id;
		this.phrases = Lists.newArrayList();
		this.phrases.add(label);
	}

	public RouteResult(String provider, String id, int rank, String label, Map<String, Object> context) {
		this.provider = provider;
		this.id = id;
		this.rank = rank;
		this.label = label;
		this.context = context;
	}

	public String getProvider() {
		return provider;
	}

	public String getId() {
		return id;
	}

	public int getRank() {
		return rank;
	}

	public String getLabel() {
		return label;
	}


	public Map<String, Object> getContext() {
		return context;
	}

	/**
	 * Get phrases which should be compared to queries phrase
	 */
	public List<String> getPhrases() {
		return ImmutableList.copyOf(phrases);
	}

	public RouteResult addPhrase(String phrase) {
		if (StringUtils.isNotBlank(phrase)) {
			phrases.add(phrase);
		}

		return this;
	}

	/**路由文件名稱*/
	private String routeFileName;
	/**路由名*/
	private String routeName;

	/**原路由*/
	private String originName;

	/**目的路由*/
	private String destNames;


	private String routeDesc;

	public String getRouteName() {
		return routeName;
	}

	public String getOriginName() {
		return originName;
	}

	public String getDestNames() {
		return destNames;
	}

	public RouteResult(String id,String routeFileName,  String routeName, String routeDesc, String originName, String destNames, String state) {
		provider = "";
		label = "";
		this.id = id;
		this.routeFileName = routeFileName;
		this.routeName = routeName;
		this.originName = originName;
		this.destNames = destNames;
		this.state = state;
		this.routeDesc = routeDesc;
	}

	public String getState() {
		return state;
	}

	public enum RouteState {
		ACTIVE(32),INSTALLED(2), UNINSTALLED(1), RESOLVED(4), STARTING(8), STOPPING(16);
		private int index;

		RouteState(int index) {
			this.index = index;
		}

		public static String getNameByIndex(int index) {
			for (RouteState state : RouteState.values()) {
				if (index == state.index) {
					return state.name();
				}
			}
			return "";
		}
	}

	public void setId(String id) {
		this.id = id;
	}

	public void setProvider(String provider) {
		this.provider = provider;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	public void setState(String state) {
		this.state = state;
	}

	public void setContext(Map<String, Object> context) {
		this.context = context;
	}

	public void setRank(int rank) {
		this.rank = rank;
	}

	public void setPhrases(List<String> phrases) {
		this.phrases = phrases;
	}

	public void setRouteName(String routeName) {
		this.routeName = routeName;
	}

	public void setOriginName(String originName) {
		this.originName = originName;
	}

	public void setDestNames(String destNames) {
		this.destNames = destNames;
	}

	public String getRouteDesc() {
		return routeDesc;
	}

	public void setRouteDesc(String routeDesc) {
		this.routeDesc = routeDesc;
	}

	public String getRouteFileName() {
		return routeFileName;
	}

	public void setRouteFileName(String routeFileName) {
		this.routeFileName = routeFileName;
	}

	@Override
	public String toString() {
		return "RouteResult{" +
				"id='" + id + '\'' +
				", provider='" + provider + '\'' +
				", label='" + label + '\'' +
				", state='" + state + '\'' +
				", context=" + context +
				", rank=" + rank +
				", phrases=" + phrases +
				", routeFileName='" + routeFileName + '\'' +
				", routeName='" + routeName + '\'' +
				", originName='" + originName + '\'' +
				", destNames='" + destNames + '\'' +
				", routeDesc='" + routeDesc + '\'' +
				'}';
	}
}
